package com.basker.pisces.springcloud.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.basker.pisces.springcloud.signature.SignatureGenerateInterceptor;
import com.basker.pisces.springcloud.signature.SignatureValidateInterceptor;
import com.basker.pisces.springcloud.signature.SignatureValidator;

/**
 * 服务签名相关的配置
 *
 * @author hangwen
 */
@Configuration
public class SignatureConfig {

    @Bean
    public SignatureGenerateInterceptor signatureInterceptor() {
        return new SignatureGenerateInterceptor();
    }

    @Bean
    @ConditionalOnProperty(value = "pisces.signature.validate.enable", matchIfMissing = true)
    public SignatureValidateInterceptor signatureValidateInterceptor() {
        return new SignatureValidateInterceptor();
    }

    @Bean
    @ConditionalOnBean(SignatureValidateInterceptor.class)
    public SignatureValidator signatureValidator() {
        return new SignatureValidator();
    }

}
